<template>
  <div class="dialog-overlay">
    <div class="dialog">
      <div class="dialog-header">
        <span class="dialog-title">确定退单吗？</span>
      </div>

      <div class="dialog-content">
        <div style="margin-left: 10px;margin-bottom: 10px;font-weight: bold;">退单原因:</div>
        <div class="dialog-buttons">
          <div
              class="dialog-button"
              :class="{'selected': selectedIndex === 0}"
              @click="selectReason(0)">
            联系不上
          </div>
          <div
              class="dialog-button"
              :class="{'selected': selectedIndex === 1}"
              @click="selectReason(1)">
            需求不详
          </div>
          <div
              class="dialog-button"
              :class="{'selected': selectedIndex === 2}"
              @click="selectReason(2)">
            其他原因
          </div>
        </div>
        <textarea class="dialog-content-input" placeholder="请输入补充说明"></textarea>
      </div>

      <div class="dialog-footer">
        <div class="footer-button" @click="cancel">
          取消
        </div>
        <div class="separator"></div>
        <div class="footer-button confirm" @click="confirm">
          确定
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { defineProps, defineEmits, ref } from 'vue';

// 定义组件的 props
const props = defineProps({
  visible: {
    type: Boolean,
    required: true,
  },
  money: {
    type: Number,
    required: true,
  },
});

// 定义组件的事件
const emit = defineEmits(['onClickCancel', 'onClickConfirm']);

// 选中的按钮索引
const selectedIndex = ref(null);

// 取消按钮点击事件
function cancel() {
  emit('onClickCancel', false); // 触发关闭事件
}

// 确定按钮点击事件
function confirm() {
  emit('onClickConfirm', false); // 触发关闭事件
  console.log('支付已确认');
}

// 选择退单原因
function selectReason(index) {
  selectedIndex.value = index;
}
</script>

<style scoped>
.dialog-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.dialog {
  background-color: white;
  border-radius: 12px;
  width: 80%;
  max-width: 400px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.dialog-header {
  padding: 20px;
  text-align: center;
}

.dialog-title {
  font-size: 16px;
  font-weight: bold;
  color: black;
}

.dialog-content {
  display: flex;
  flex-direction: column;
}

.dialog-buttons {
  display: flex;
  flex-direction: row;
  align-items: center;
  padding-right: 10px;
}

.dialog-button {
  flex: 1;
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  height: 40px;
  width: 80px;
  border-radius: 5px;
  background-color: #F4F5F6;
  margin-left: 10px;
  font-size: 14px;
  cursor: pointer;
  transition: background-color 0.3s;
}

.dialog-button.selected {
  background-color: #FF4142; /* 选中时背景色 */
  color: white; /* 选中时字体颜色 */
}

.dialog-content-input {
  height: 150px;
  border: 0px;
  background-color: #F4F5F6;
  margin: 10px;
  padding: 10px;
  font-size: 14px;
}

.dialog-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid #d1d3d5;
}

.footer-button {
  flex: 1;
  text-align: center;
  padding: 16px;
  font-size: 14px;
  cursor: pointer;
}

.footer-button.confirm {
  color: red;
  font-weight: bold;
}

.separator {
  width: 1px;
  height: 48px;
  background-color: #d1d3d5;
}
</style>
